﻿
//服务器消息监听
var msgBuffer=""; //全局变量，存储缓冲消息
function MSGManage() {
    msgBuffer += this.req.responseText;
    
    if (msgBuffer == "") return;
    var msg = msgBuffer.split("<$$$MSG$$$>"); //将一堆消息分开
    msgBuffer = "";
    for (var i = 0; msg[i] != undefined; i++) { 
        var m = msg[i].split("<$$$##$$$>"); 
        if (document.getElementById(m[0] + "_chatWindow_OutPut") != null) {
            document.getElementById(m[0] + "_chatWindow_OutPut").value += m[0] + " : " + m[2] + '\n';
            document.getElementById(m[0] + "_chatWindow_OutPut").scrollTop = document.getElementById(m[0] + "_chatWindow_OutPut").scrollHeight;
        }
        else { //聊天窗口没有打开，重新格式信息放到缓冲区
            msgBuffer += m[0] + "<$$$##$$$>" + m[1] + "<$$$##$$$>" + m[2] + "<$$$MSG$$$>";
        }
    }
 }

function ListenMSG() {
    name = document.getElementById("name").value;
    var url = "AjaxResponse/GetMSG.aspx?name=" + name;
    new ContentLoader(url, MSGManage);
 }

